package com.itheima.service.mongo.impl;

import com.itheima.domain.mongo.Sound;
import com.itheima.service.mongo.SoundService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

/**
 * 语音service层实现类：
 */
@Service
public class SoundServiceImpl implements SoundService {

    @Autowired
    private MongoTemplate mongoTemplate;

    /**
     * 发送语音：
     * @param sound
     */
    @Override
    public void saveSound(Sound sound) {

        sound.setCreated(System.currentTimeMillis());
        mongoTemplate.save(sound);
    }


    /**
     * 接收语音：
     *
     * @return
     */
    @Override
    public List<Sound> receiveSound() {
        Query query = new Query();
        return mongoTemplate.find(query, Sound.class);

    }
}
